package com.zbkj.admin.controller.merchant.shop;

import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.model.merchant.Merchant;
import com.zbkj.common.model.shop.EbGroupPurchase;
import com.zbkj.common.model.user.User;
import com.zbkj.common.request.EbGroupPurchaseRequest;
import com.zbkj.common.response.EbGroupPurchaseResponse;
import com.zbkj.common.response.EbGroupPurchaseStatisticsVo;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.utils.SecurityUtil;
import com.zbkj.service.service.EbGroupPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/api/admin/merchant/ebGroupPurchase")
@Api(tags = "团购管理")
public class MerchantGroupPurchaseController {
    @Resource
    EbGroupPurchaseService ebGroupPurchaseService;



    /**
     * 上下架
     *
     * @param ebGroupPurchaseRequest
     * @return
     */
    @ApiOperation(value = "上下架")
    @PostMapping(value = "/updateStatus")
    public CommonResult<Integer> updateStatus(@RequestBody EbGroupPurchaseRequest ebGroupPurchaseRequest) {
        ebGroupPurchaseService.updateStatus(ebGroupPurchaseRequest);
        return CommonResult.success(1);
    }


    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询详情")
    @GetMapping(value = "/get/{id}")
    public CommonResult<EbGroupPurchaseResponse> get(@PathVariable("id") Long id) {
        return CommonResult.success(ebGroupPurchaseService.getById(id));
    }


    @ApiOperation(value = "分页查询列表")
    @PostMapping(value = "/getPage")
    public CommonResult<PageInfo<EbGroupPurchaseResponse>> getPage(@RequestBody EbGroupPurchaseRequest ebGroupPurchaseRequest) {
        SystemAdmin systemAdmin = SecurityUtil.getLoginUserVo().getUser();
        ebGroupPurchaseRequest.setMerId(systemAdmin.getMerId());
        return CommonResult.success(ebGroupPurchaseService.getPlatformPage(ebGroupPurchaseRequest));
    }
    @ApiOperation(value = "查询统计信息")
    @GetMapping(value = "/getShopStatistics")
    public CommonResult<EbGroupPurchaseStatisticsVo> getShopStatistics() {


        return CommonResult.success(ebGroupPurchaseService.getShopStatistics(-1));
    }
}